<template>
	<view class="check">
		<u--form ref="form_ref" :model="formData1" :rules="rules" labelWidth=0>
			<!-- 通过prop属性 指定当前表单元素 按照什么规则进行校验 prop="键名" -->
			<u--text text="姓名"></u--text>
			<u-form-item  prop="">
				<u--input v-model="formData1.userName" placeholder="请输入姓名" border="surround" clearable></u--input>
			</u-form-item>

			<u--text text="是否接触过可疑人员"></u--text>
			<u-form-item>
				<u-radio-group v-model="formData1.contact" placement="row">
					<!--:label是你要显示的，:name是真正的值  -->
					<u-radio activeColor="green" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1"
						:key="index" :label="item.name" :name="item.value" ></u-radio>
				</u-radio-group>
			</u-form-item>

			<u--text text="从何而来"></u--text>
			<u-form-item prop="">
				<u--input v-model="formData1.fromAddress" placeholder="请输入地址" border="surround" clearable></u--input>
			</u-form-item>

			<u--text text="现居地址"></u--text>
			<u-form-item prop="">
				<u--input v-model="formData1.nowAddress" placeholder="请输入地址" border="surround" clearable></u--input>
			</u-form-item>

			<u--text text="身体状况"></u--text>
			<u-form-item prop="">
				<u-radio-group v-model="formData1.status" placement="row">
					<u-radio activeColor="green" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist2"
						:key="index" :label="item.name" :name="item.value" ></u-radio>
				</u-radio-group>
			</u-form-item>

			<u--text text="今日体温"></u--text>
			<u-form-item >
				<u--input v-model="formData1.temperature" placeholder="请输入体温" border="surround" clearable></u--input>
			</u-form-item>

			<u--text text="疫苗接种情况"></u--text>
			<u-form-item prop="">
				<u-radio-group v-model="formData1.vaccin" placement="row">
					<u-radio activeColor="green" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist3"
						:key="index" :label="item.name" :name="item.value" ></u-radio>
				</u-radio-group>
			</u-form-item>

		</u--form>

		<u-button class="btn" text="提交" type="primary" @click="submit"></u-button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				rules: {
					// 字段名称
					'wendu': [
						{	type:'number',
							required: true, 
							message: '温度请输入数字',
							trigger: ['blur', 'change']
						}
					]
				},
				formData1: {
					userName:"",
					id:0,
					contact: 0,
					fromAddress: "",
					nowAddress: "",
					status: 5,
					temperature: "",
					vaccin: 4,
					
					userId: 0,
					createTime: "",
					dangerArea: true,
				},
				formData2: {
					userName:"",
					id: 0,
					contact: 0,
					fromAddress: "",
					nowAddress: "",
					status: 5,
					temperature: "",
					vaccin: 4,
					
					userId: 0,
					createTime: "",
					dangerArea: true,
				},
				radiolist1: [{
						name: '是',
						disabled: false,
						value:true
					},
					{
						name: '否',
						disabled: false,
						value : false,
					}
				],
				radiolist2: [{
						name: '健康',
						disabled: false,
						value:0
					},
					{
						name: '一般',
						disabled: false,
						value:1
					},
					{
						name: '疑似',
						disabled: false,
						value:2
					},
					{
						name: '确诊',
						disabled: false,
						value:3
					},
					{
						name: '居家隔离',
						disabled: false,
						value:4
					}
				],
				radiolist3: [{
						name: '未接种',
						disabled: false,
						value:0
					},
					{
						name: '一针',
						disabled: false,
						value:1
					},
					{
						name: '二针',
						disabled: false,
						value:2
					},
					{
						name: '三针',
						disabled: false,
						value:3
					}
				],

				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
			}
		},
		methods: {
			//1.表单提交的方法 需求：点击提交按钮 通过表单校验 才发送请求提交举报
			submit(){
				// 想要拿到某个标签的dom结点{VueComponent } 1.form表单添加ref属性=xx 2.this.$refs.xx
			this.$refs.form_ref.validate().then(res => {
				// uni.$u.toast('校验通过')
				// 校验通过 发请求
				uni.request({
					url:"http://blog.coldworld.top:8081/healthinfo/add",
					method:"POST",
					data:this.formData1,
					success: (res) => {
						console.log(res)
						if(res.data.code==20000){
						// 提示用户添加信息成功
						uni.$u.toast('添加信息成功')
						// 拿到form表单dom结点 重置表单
						// this.$refs.form_ref.resetFields()
						this.formData1 =this.formData2
						}else{
							let msg =res.data.message
							uni.$u.toast(msg)
						}
					}
				})
			}).catch(errors => {
				uni.$u.toast('请规范填写内容')
			})						
			},
		},
		onLoad() {
			let id = uni.getStorageSync()
			console.log(id)
		}
	}
</script>

<style lang="scss">
	.check {
		padding: 20rpx;
		// font-weight: bold;
		.btn {
			margin-top: 20rpx;
		}
	}
</style>
